<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

<head>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
  <title>Intro to CIUnit (part of fooStack) for CodeIgniter</title>
</head>

<style>
body {
  width: 750px;
  margin: 0px auto auto 100px;
  background-color: #000000;
}
#wrapper {
  padding : 16px 50px 50px 50px;
  margin-top: 0px;
  background-color: #ffffff;
  border-left-style: groove; 
  border-left-color: green; 
  border-left-width: 15px; 
  border-right-style: ridge; 
  border-right-color: green; 
  border-right-width: 15px; ;
}
</style>

<body>

<div id="wrapper">
<!--
/*
* fooStack, Codeigniter Plugin for Unit testing and more
* Copyright (c) 2008-2009 Clemens Gruenberger,
* <clem@fragment.at>
* Released under the MIT license, see:
* http://www.opensource.org/licenses/mit-license.php
*/
-->

<h1>fooStack for CodeIgniter</h1>
<h2>CIUnit: Unit testing for CodeIgniter</h2>
<p>
CIUnit is a cool bridge between your CodeIgniter application and phpUnit.
</p>


<ul>
  <li>CodeIgniter 1.6.0+ ( tested with 1.6.X, 1.7.0, 1.7.1 and <b>1.7.2</b> )</li>
  <li>PHP 5.1+</li>
</ul>

<p><a href="fooStack_v0.17.zip">Download the current <b>fooStack v0.17</b> - for CI 1.7.2 here!</a></p>
<p><a href="fooStack_v0.15.zip">Download the slightly outdated <b>fooStack v0.15</b> here - for CI 1.6.X, 1.7.1</a></p>
<b>For v0.15.zip please be aware that the installation is slightly different! Have a look at the index.html file included in fooStack_v0.15.zip</b>

<p style='font-size: 0.9em; font-style: italic;'>(The cutting edge development version and older versions are accessible through 
the public mercurial repository at <a href="http://www.bitbucket.org/rafsoaken/ciunit/overview/">bitbucket.org / ciunit</a>)</p>

<p>
<h2>2 minute Setup:</h2>
</p>

<ol>
  <li>Download and unzip the fooStack package in a temporary folder</li>
  <li>Copy the fooStack directory in your "YourProject/system/application/libraries" directory</li>
  <li>Copy the tests directory in your "YourProject/system/application" directory</li>
  <li>If you don't use the standard layout for your CodeIgniter project, change the first 2 paths in the file "YourProject/system/application/libraries/fooStack/fooBase/index.php"</li>
  <li>Replace the line that starts with <pre>$active_group =</pre> in your database.php ("YourProject/system/application/config" directory) with:<br />

<pre>
$env_used = 'default'; //name of your development setting
if(defined('CIUnit_Version')){
  $env_used .= '_test';
}
$active_group = $env_used;</pre></li>
  
  <li>Create a new database setting that will act as the test database (it will always be cleared when you run tests!), 
  that is named like your development setting but with a trailing '_test'. <b>Note:</b> CIUnit fixtures will insist on the trailing '_test' to prevent accidental data loss.</li> 
    
</ol>

<p><b>Congratulations you are done with setting up fooStack!</b></p>
<p>Oh, wait, do you have phpUnit already installed?</p> 
<p><a href="http://www.phpunit.de/manual/current/en/installation.html">http://www.phpunit.de/manual/current/en/installation.html</a></p>

<p>Once you have fooStack and phpUnit running:</p>

<h3>Run tests:</h3>
<ul>
  <li>Run all tests from within the tests directory: "phpunit AllTests.php", or use "phpunit --verbose AllTests.php" for more detailed output</li>
  <li>Run only a subgroup of tests, eg model tests, go into the tests/models directory and run "phpunit ModelAllTests.php"</li>
  <li>Consequently, for running just one particular test, change to this test's directory and type "phpunit testSomeStuff.php"</li>  
</ul>

<h3>Generating database fixtures:</h3>
<p>
Given you have tables in your test database (you should have the same as in the development database!), you can generate empty yaml fixtures like so:
From within the tests directory type (make sure the fixtures directory is writable!):
<pre>php generate fixtures</pre>
The fixture files are then available in the tests/fixtures directory.
</p>
<p>
Using the fixtures is easy:
Fill the yaml fixture files with the fixture data needed (<a href="http://en.wikipedia.org/wiki/YAML">yaml is a easily readable format for your data</a>). 
Once this is done, call e.g. <pre>$this->dbfixt('items', 'comments', 'users'); </pre> from within the test setup function. Then these table fixtures are assured to be loaded into your test database AND are available as test variables like so:
<pre>$this->items_fixt, $this->comments_fixt, $this->users_fixt.</pre> E.g the second row of data in the comments table in your tests database 
is also available through <pre>$this->comments_fixt['second'];</pre>
</p>

<h3>CIUnit tests itself</h3>
<p>
Without writing any tests, typing "phpunit CIUnitAllTests.php" from within the "YourProject/application/tests/ciunit" directory will already run a couple of tests - these make sure that CIUnit is correctly installed and works as expected.
</p>

</div>
</body>

</html>